home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: automatic charrs
- Date: 28 Feb 1996 14:44:04 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4h2ba4$ft0@umbc9.umbc.edu>
- References: <4glp29$dsh@d2.tufts.edu>
- NNTP-Posting-Host: umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- Roberto Dorich <rdorich@emerald.tufts.edu> wrote:
- |> Could someone enlighten me, and tell me why the following program runs
- |> just dandy using Sun's cc (3.0.1), but crashes using gcc (?) ?
-
- Dumb luck? Writing illegal code usually produces unpredictable behavior
- which sometimes turns out to be what was originally expected. This does
- not mean you will always be so lucky.
-
- |> #include <stdio.h>
- |> char *b() { return "Hello";}
- |>
- |> main() {
- |> char *a=b();
-
- No problem there...
-
- |> a[0]='X';
-
- Here's the culprit! The string "Hello" is constant and as such is not legally
- modified.
-
- |> printf("--> %s\n",a);
- |> }
-
- <rest deleted>
-
- I don't even know if your Sun compiler is ANSI because your functions
- parameters were not explicitly defined. However, either make "Hello" a local
- static array of char or find some other way of doing whatever it si you
- are trying to do.
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-